﻿using System;
using ICommonLibrary.Service;

namespace ICommonLibrary.Cache {

    public interface ICache : IService {

        /// <summary>
        /// Attempt to retrieve an object from the cache.
        /// </summary>
        /// <param name="key"></param>
        /// <returns>an object or default(T)</returns>
        T Get<T>(string key);

        T Get<T>(string key, Func<T> itemCreator, bool cacheNewItem);

        T Get<T>(string key, Func<T> itemCreator, TimeSpan expiration, bool cacheNewItem);

        /// <summary>
        /// Evict an item from the cache immediately.
        /// </summary>
        /// <param name="key"></param>
        void Remove(string key);

        /// <summary>
        /// Add an item to the cache.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        void Put(string key, object value);

        /// <summary>
        /// Add an item to the cache with expiration specified.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="expiration"></param>
        void Put(string key, object value, TimeSpan expiration);

        /// <summary>
        /// Get an approximate number of items cached in this cache.
        /// </summary>
        /// <returns></returns>
        int Size{ get;}

        /// <summary>
        /// Evict all items from the cache immediately.
        /// </summary>
        void Clear();
    }
}